﻿using System;

using Sunyi.Project.WebPoint.DataAccess;
using Sunyi.Project.WebPoint.DataContract;

namespace Sunyi.Project.WebPoint.DataAccessController
{
    public abstract class BaseDaoController<Entity,Dao>
        where Entity : class, IDataEntity
        where Dao : IDao<Entity>, new()
    {
        protected Dao dao = new Dao();

        public virtual Entity Select(Guid id)
        {
            return dao.Select(id);
        }

        public virtual void Insert(Entity entity)
        {
            if (entity.Id == Guid.Empty) entity.Id = Guid.NewGuid();

            dao.Insert(entity);
        }

        public virtual void Update(Entity entity)
        {
            dao.Update(entity);
        }

        public virtual void Delete(Guid id)
        {
            dao.Delete(id);
        }

        protected virtual void FillEntity(Entity entity) { }
    }
}
